Assign contextual parameter types to functions with type parameters#61792
Closed
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Closed
Assign contextual parameter types to functions with type parameters#61792Andarist wants to merge 5 commits intomicrosoft:mainfrom
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enables contextual typing for function expressions that introduce type parameters and updates related tests and compiler logic to reflect this change.
- Updates fourslash tests to expect generic parameter
Tinstead ofany. - Adds new compiler tests covering contextual typing of generic functions and generators.
- Removes exclusions for functions with type parameters in context-sensitivity checks.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/cases/fourslash/contextualTypingGenericFunction1.ts | Updated expected quickInfo for generic parameter contexts |
| tests/cases/compiler/contextualTypingGenericFunction2.ts | Added new tests for contextual typing of functions with type params |
| src/compiler/utilities.ts | Removed exclusion of type-parameterized functions from context checks |
| src/compiler/checker.ts | Removed type-parameter guard in return-expression context check |
Comments suppressed due to low confidence (2)
src/compiler/utilities.ts:10785
- Update the function-level comment to reflect that functions with type parameters are now considered context-sensitive. For example, document why the previous exclusion was removed and reference issue #61791.
export function hasContextSensitiveParameters(node: FunctionLikeDeclaration): boolean {
src/compiler/checker.ts:21027
- Add or update a comment explaining that functions with type parameters now participate in contextual return typing and why the
node.typeParameterscheck was removed.
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
…types-for-generic-functions
Andarist
commented
Jun 25, 2025
This reverts commit b97406f.
…empt to hoist inferred type parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #61791